package com.rongshu.view.home.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.widget.RelativeLayout;

import com.rongshu.R;
import com.rongshu.utils.Constant;
import com.rongshu.view.base.BaseActivity;
import com.rongshu.view.home.adapter.pageradapter.PreviewImgPageAdapter;
import com.utils.DensityUtil;

import java.util.List;

import butterknife.BindView;

public class PreviewImgActivity extends BaseActivity {
    @BindView(R.id.viewPager)
    ViewPager viewPager;
    //imgList
    private List<String> imgPaths = null;
    //index img
    private String currentImgs = null;
    //intent
    private Intent intent = null;
    //pageradapter
    private PreviewImgPageAdapter adapter = null;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        hintTitleBar();
    }

    @Override
    protected int initLayout() {
        return R.layout.activity_preview_img_view;
    }

    @Override
    protected void initView() {
        intent = getIntent();
        if (intent == null) {
            finish();
            overridePendingTransition(R.anim.hold, R.anim.zoom_in_exit);
            return;
        }
        //margin
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) viewPager.getLayoutParams();
        int toolbarHeight = DensityUtil.getStateBar(this);
        layoutParams.setMargins(0, toolbarHeight, 0, 0);
        imgPaths = intent.getStringArrayListExtra(Constant.INTENT_DATA);
        currentImgs = intent.getStringExtra(Constant.INTENT_MESSAGE);
        adapter = new PreviewImgPageAdapter(imgPaths);
        viewPager.setAdapter(adapter);
        //遍历查看图片的position位置
        if (imgPaths != null && !imgPaths.isEmpty()) {
            for (int i = 0; i < imgPaths.size(); i++) {
                if (TextUtils.isEmpty(currentImgs)) {
                    viewPager.setCurrentItem(0);
                } else {
                    if (imgPaths.get(i).equals(currentImgs)) {
                        viewPager.setCurrentItem(i);
                    }
                }
            }
        }
    }

    @Override
    protected void initData() {
    }

    @Override
    protected void updateViews(boolean isRefresh) {

    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        overridePendingTransition(R.anim.hold, R.anim.zoom_in_exit);
    }
}
